package com.smart.upload.util;

import java.util.HashMap;
import java.util.Map;

import com.smart.upload.bean.UserInfo;

public class UploadSessionUtil {

	private static final ThreadLocal<Map<String, Object>> threadLocal=new ThreadLocal<Map<String, Object>>();
	
	private static final String userInfoKey="_user_info";
	private static final String queryParamsKey="_query_params";
	
	public static UserInfo getUserInfo() {
		
		Map<String, Object> threadLocalData=threadLocal.get();
		return (UserInfo) threadLocalData.get(userInfoKey);
	}
	
	public static void setUserInfo(UserInfo userInfo) {
		
		Map<String, Object> threadLocalDataMap=threadLocal.get();
		if(threadLocalDataMap==null){
			threadLocalDataMap=new HashMap<String, Object>();
		}
		threadLocalDataMap.put(userInfoKey, userInfo);
		threadLocal.set(threadLocalDataMap);
	}
	
	@SuppressWarnings("unchecked")
	public static Map<String, Object> getQueryParams() {
		
		Map<String, Object> threadLocalData=threadLocal.get();
		return (Map<String, Object>) threadLocalData.get(queryParamsKey);
	}
	
	public static void setQueryParams(Map<String, Object> queryParams) {
		
		Map<String, Object> threadLocalDataMap=threadLocal.get();
		if(threadLocalDataMap==null){
			threadLocalDataMap=new HashMap<String, Object>();
		}
		threadLocalDataMap.put(queryParamsKey, queryParams);
		threadLocal.set(threadLocalDataMap);
	}
	
}
